package com.git_demo.controller;

import com.git_demo.bean.Classes;
import com.git_demo.service.ClassService;
import org.apache.dubbo.config.annotation.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * @author 金振宇
 * @describe
 */
@Controller
@RequestMapping("class")
public class ClassController {

    private Logger logger = LoggerFactory.getLogger(StudentController.class);

    @Reference(url = "dubbo://localhost:20880")
    ClassService classService;

    @RequestMapping("findClass")
    public String findClass(Model model){
        try {
            logger.info("查询所有班级");
           List<Classes> classesList = classService.findAllClasses();
           model.addAttribute("classesList",classesList);
            return "index_class";
        }catch (Exception e){
            logger.error("查询所有班级异常",e);
        }
        return "redirect:/erro.html";
    }

    @RequestMapping("addClass")
    public String addClass(Classes classes){
        try {
            logger.info("添加班级",classes);
            classService.addClass(classes);
            return "redirect:/class/findClass";
        }catch (Exception e){
            logger.error("添加班级失败",e);
        }
        return "redirect:/erro.html";
    }
}
